package com.mejlisse.gwt.scaffold.generated;

import com.google.gwt.app.place.AbstractRecordListView;
import com.google.gwt.app.place.PropertyColumn;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.DateTimeFormatRenderer;
import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.mejlisse.gwt.request.NewsRecord;
import com.mejlisse.gwt.shared.Category;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link AbstractRecordListView} specialized to {@link NewsKey}} values.
 */
public class NewsListView extends AbstractRecordListView<NewsRecord> {
	interface Binder extends UiBinder<HTMLPanel, NewsListView> {
	}

	private static final Binder BINDER = GWT.create(Binder.class);

	@UiField CellTable<NewsRecord> table;
	@UiField Button newButton;
  
	public NewsListView() {
		init(BINDER.createAndBindUi(this), table, newButton, getColumns());
	}

	protected List<PropertyColumn<NewsRecord, ?>> getColumns() {
		// TODO These should be <g:col> elements in a <g:table> in the ui.xml file

		List<PropertyColumn<NewsRecord, ?>> columns = new ArrayList<PropertyColumn<NewsRecord, ?>>();
		
	    columns.add(new PropertyColumn<NewsRecord, java.lang.String>(NewsRecord.accroche, new AbstractRenderer<java.lang.String>() {
      public String render(java.lang.String obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));
	    columns.add(new PropertyColumn<NewsRecord, java.lang.String>(NewsRecord.article, new AbstractRenderer<java.lang.String>() {
      public String render(java.lang.String obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));
	    columns.add(new PropertyColumn<NewsRecord, com.mejlisse.gwt.shared.Category>(NewsRecord.categ, new AbstractRenderer<com.mejlisse.gwt.shared.Category>() {
      public String render(com.mejlisse.gwt.shared.Category obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));
	    columns.add(new PropertyColumn<NewsRecord, java.util.Date>(NewsRecord.newsDate, new DateTimeFormatRenderer(DateTimeFormat.getShortDateFormat())));
	    columns.add(new PropertyColumn<NewsRecord, java.lang.String>(NewsRecord.source, new AbstractRenderer<java.lang.String>() {
      public String render(java.lang.String obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));
	    columns.add(new PropertyColumn<NewsRecord, java.lang.String>(NewsRecord.titre, new AbstractRenderer<java.lang.String>() {
      public String render(java.lang.String obj) {
        return obj == null ? "" : String.valueOf(obj);
      }    
}));		
	    return columns;
	}
}
